using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.MediaCenter;
using Microsoft.MediaCenter.Hosting;
using Microsoft.MediaCenter.UI;

namespace Ladenius.Series.Mce {
    public class Application : ModelItem {
        private static Application singleApplicationInstance;
        private AddInHost host;
        private HistoryOrientedPageSession session;

        public Application()
            : this(null, null) {
        }

        public Application(HistoryOrientedPageSession session, AddInHost host) {
            this.session = session;
            this.host = host;
            singleApplicationInstance = this;
        }

        public MediaCenterEnvironment MediaCenterEnvironment {
            get {
                if (host == null) return null;
                return host.MediaCenterEnvironment;
            }
        }

        public void GoToMenu() {
            Dictionary<string, object> properties = new Dictionary<string, object>();
            properties["Application"] = this;

            if (session != null) {
                session.GoToPage("resx://Ladenius.Series.Mce/Ladenius.Series.Mce.Resources/Menu", properties);
            } else {
                Debug.WriteLine("GoToMenu");
            }
        }

        public void DialogTest(string strClickedText) {
            int timeout = 5;
            bool modal = true;
            string caption = Resources.DialogCaption;

            if (session != null) {
                MediaCenterEnvironment.Dialog(strClickedText,
                                              caption,
                                              new object[] { DialogButtons.Ok },
                                              timeout,
                                              modal,
                                              null,
                                              delegate(DialogResult dialogResult) { });
            } else {
                Debug.WriteLine("DialogTest");
            }
        }

        public string[] MyData {
            get {
                return new string[4] { "Alpha", "Bravo", "Charlie", "Delta" };
            }
        }
    }
}